<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="icon" href="/ttpstatic/favicon.ico">
  <title>e安行实训平台</title>
  {% load static %}
  <link rel="stylesheet" type="text/css" href="{% static 'css/base.css' %}">
  <style>
    #getVerifyCode{
      width: 160px;
      float:left;
      height: 45px;
      background-color: #ff9900;
      color: #ffffff;
      border-radius: 5px;
      margin-top: 20px;
      border: none;
    }
    #getVerifyCode:disabled {
      background-color: #ccc;
    }
    form > p{
      width: 100%;
      display: flex;
      flex-direction: row;
      justify-content: space-between;
      align-items: center;
    }
    .error-msg{
  color: red;
}
    #phone-msg{
      font-size: 12px;
      color: red;
    }
  </style>
</head>
<body>
  <div id="main">
    <h2>
      e安行实训平台
    </h2>
    <div id="con">
      <div id="login-pwd">
        <h3>账号密码登录</h3>
        <form method="POST" action={% url 'study:login' %}>
          <input type="hidden" class="csrf_token" name="csrf_token" />
          <input type="hidden" class="user_type" name="user_type"  value='T'/>
          <p>
            <input type="text" required placeholder="请输入手机号" id="phone" class="phone" name="phone" />

          </p>
          <p>
            <span id="phone-msg"></span>
          </p>
          <input type="password" required placeholder="请输入密码" class="phone" name="verifyCode" />
            {% if error %}
          <p class="error-msg">
            {{error}}
          </p>
          {% endif %}
          <input id="submit" type="submit" value="登 录">
        </form>
        <div id="links" style="justify-content: flex-end;">
        </div>
      </div>
    </div>
  </div>
  <script src="/ttpstatic/js/js-cookie.js"></script>
  <script src="/ttpstatic/study/layui/layui.js" charset="utf-8"></script>
  <script src="/ttpstatic/js/tools.js"></script>
  <script>
    var interval;
    var secs = 60;
    var counting = false;
    var layer
    verifyBtn = document.getElementById('getVerifyCode')
    layui.use('layer', function(){
      layer = layui.layer;
    });
    verifyBtn.addEventListener('click', function() {
      if(counting) return;
      var phoneDom = document.getElementById('phone')
      if(!(/^1\d{10}$/.test(phoneDom.value))){
        showErr("phone", "请输入正确手机号");
        return false;
      }
      counting= true;
      _post("{% url 'study:getVerifyCode' %}", {phone: phoneDom.value}, function(res){
          return
        interval = setInterval(function() {
          verifyBtn.value = secs-- + 's后重新获取';
          verifyBtn.disabled = true
          if(secs<=0) {
            clearInterval(interval);
            verifyBtn.value = '获取短信验证码';
            verifyBtn.disabled = false
            secs = 60;
            counting = false;
          }
        }, 1000)
      }, function(res){
        counting = false;
      })
    })
  </script>
</body>
</html>